# -*- coding: utf-8 -*-
# @File      :2
# @Author    :liaogan
# @Datetime  :2023/3/21 11:06

"""
以下是 Python 代码实现，使用了滑动窗口的思想：
"""
def longestSubstring(s):
    n = len(s)
    # 使用一个字典记录每个字符最后一次出现的位置
    last = {}
    start = res = 0
    for i in range(n):
        if s[i] in last and last[s[i]] >= start:
            start = last[s[i]] + 1
        last[s[i]] = i
        res = max(res, i - start + 1)
    return res


print(longestSubstring("abcabcbb"))
print(longestSubstring("bbbbb"))
print(longestSubstring("ASDOKKAASD"))
